<?php
/*
 * Copyright 2008 by Oliver Radwan, Maxwell Palmer, Nolan McNair,
 * Taylor Talmage, and Allen Tucker.  This program is part of RMH Homebase.
 * RMH Homebase is free software.  It comes with absolutely no warranty.
 * You can redistribute it and/or modify it under the terms of the GNU
 * General Public License as published by the Free Software Foundation
 * (see <http://www.gnu.org/licenses/ for more information).
*/

/**
 * Person class for RMH scheduler.
 * @author Oliver Radwan and Allen Tucker
 * @version May 1, 2008
 */

class Person {
	private $id; 		 // id (unique key) = first_name . phone1
	private $first_name; // first name as a string
	private $last_name;  // last name as a string
	private $address; 	 // address - string
	private $city; 		 // city - string
	private $state; 	 // state - string
	private $zip; 		 // zip code - integer
	private $phone1; 	 // main phone
	private $phone2; 	 // alternate phone
    private $email; 	 // email address as a string
	private $type;       // array of "applicant", "volunteer", "sub", "guestchef", "manager"
	
	
	// new variables
	private $status;			//either active or inactive
	private $employer;			//current employer name
	private $contact_person;	//emergency contact
	private $contact_phone;		//emergency contact phone#
    
	
	private $background_check; 	// applicant: passed a background check?
	private $interview; 		// applicant: had an interview?
	private $shadow; 			// applicant: done shadowing?
	private $convictions;		// applicant: prior convictions?
	private $wherelived;		// applicant: states lived in for last five years
	private $experience;        // applicant: past volunteer experience
	private $motivation;		// applicant: why interested in RMH?
	private $specialties;		// applicant: special interests and skills for RMH

	private $availability; // array of day-time pairs; e.g., Mon9-12
	private $schedule;     // array of scheduled shifts; e.g.,  OneMon9-12
	private $history; 	   // array of recent dates worked; e.g., 03-12-08
	private $birthday;     // format: 03-12-08
	private $start_date;   // format: 03-12-08

	private $my_notes;	    // notes that the person or a manager can see and edit
	private $public_notes; 	// notes from a manager to the person
	private $private_notes; // notes that only the manager can see and edit
	private $password;      // password for calendar and database access: default = $id
	


	/**
	 * constructor for all persons
	 */
	function __construct($f, $l, $a, $c, $s, $z, $p1, $p2, $e, $t,
						 $st, $em, $cper, $cph,
	                     $bg, $in, $sh, $con, $whe, $exp, $mot, $spe,
                         $av, $sch, $hist, $bd, $sd,
	                     $pubn, $myn, $privn, $pass){
		$this->id = $f . $p1;
		$this->first_name = $f;
		$this->last_name = $l;
		$this->address = $a;
		$this->city = $c;
		$this->state = $s;
		$this->zip = $z;
		$this->phone1 = $p1;
		$this->phone2 = $p2;
		$this->email = $e;
		if ($t !== "")
		   $this->type = array($t);
		else $this->type = array();

		$this->employer = $em;
		$this->contact_person = $cper;
		$this->contact_phone = $cph;
		
		$this->background_check = $bg;
		$this->interview = $in;
		$this->shadow = $sh;
        $this->convictions = $con;
		$this->wherelived = $whe;
		$this->experience = $exp;
		$this->motivation = $mot;
		$this->specialties = $spe;

		if ($av !== "")
		   $this->availability = array($av);
		else $this->availability = array();
		if ($sch !== "")
		   $this->schedule = array($sch);
		else $this->schedule = array();
		if ($hist !== "")
		   $this->history = array($hist);
		else $this->history = array();

		$this->birthday = $bd;
		$this->start_date = $sd;
		$this->public_notes = $pubn;
		$this->my_notes = $myn;
		$this->private_notes = $privn;
		$this->password = $pass;  // default password == $id
		if($this->id==$this->password) $this->password = md5($this->id);
	}
	
	function get_employer(){
		return $this->employer;
	}
	function set_employer($em){
		$this->employer = $em;
	}
	function get_contact(){
		return $this->contact_person;
	}
	function set_contact($con){
		$this->contact_person = $con;
	}
	function get_contact_phone(){
		return $this->contact_phone;
	}
	function set_contact_phone($cph){
		$this->coontact_phone = $cph;
	}
	
	function get_status(){
		return $this->status;
	}
	function set_status($st){
		$this->status = $st;
	}

	function get_id(){
		return $this->id;
	}
    function get_first_name(){
		return $this->first_name;
	}
    function get_last_name(){
		return $this->last_name;
	}
    function get_address(){
		return $this->address;
	}
    function get_city(){
		return $this->city;
	}
    function get_state(){
		return $this->state;
	}
	function get_zip(){
		return $this->zip;
	}
	function get_phone1(){
		return $this->phone1;
	}
	function get_phone2(){
		return $this->phone2;
	}
    function get_email(){
		return $this->email;
	}
	/**
	 * @return type of person, an array of: "applicant","sub", etc.
	 */
	function get_type(){
		return $this->type;
	}
    function get_background_check(){
		return $this->background_check;
	}
	function get_interview(){
		return $this->interview;
	}
	function get_shadow(){
		return $this->shadow;
	}
	function get_convictions() {
		return $this->convictions;
	}
	function get_wherelived() {
		return $this->wherelived;
	}
	function get_experience() {
		return $this->experience;
	}
	function get_motivation() {
		return $this->motivation;
	}
	function get_specialties() {
		return $this->specialties;
	}
	function get_availability(){
		return $this->availability;
	}
	function get_schedule(){
		return $this->schedule;
	}
	function get_history(){
		return $this->history;
	}
	function get_birthday(){
		return $this->birthday;
	}
	function get_start_date(){
		return $this->start_date;
	}
    function get_public_notes(){
		return $this->public_notes;
	}
	function get_my_notes(){
		return $this->my_notes;
	}
	function get_private_notes(){
		return $this->private_notes;
	}
    function get_password(){
		return $this->password;
	}
	/**
	 * setters are below: notice that first name and primary phone cannot be
	 * changed, since they form the person's unique id (key) in the database
	 * Neither can birth date nor start date.
	 */
	function set_last_name($ln){
		$this->last_name=$ln;
	}
	function set_address($ad){
		$this->address = $ad;
	}
	function set_city($c){
		$this->city = $c;
	}
	function set_state($s){
		$this->state = $s;
	}
	function set_zip($z){
		$this->zip = $z;
	}
	function set_phone2($p){
		$this->phone2 = $p;
	}
	function set_email($em){
		$this->email = $em;
	}
	/**
 	 * @param $t is a type of person, like "volunteer"
 	 */
 	function add_type ($t) {
 		$this->type[] = $t;
 	}
 	/**
 	 * remove $t from type if it's there
 	 */
 	function remove_type ($t) {
 		$index = array_search($t, $this->type);
 		if ($index !== false)
 		   array_splice($this->type, $index, 1);
 	}
 	function is_type ($t) {
 		return in_array($t, $this->type);
 	}
 	/**
 	 * @param $a is a day-time pair, like "Mon9-12" to be added to the person's availability
 	 */
 	function add_availability ($a) {
 		$this->availability[] = $a;
 	}
 	/**
 	 * remove $a from the person's from a person's availability if it's there
 	 */
 	function remove_availability ($a) {
 		$index = array_search($a, $this->availability);
 		if ($index !== false)
 		   array_splice($this->availability, $index, 1);
 	}
 	function is_available ($a) {
 		return in_array($a, $this->availability);
 	}
 	/**
 	 * @param $s is a time slot, like "OneMon9-12" to be added to the person's schedule
 	 */
 	function add_schedule ($s) {
 		$this->schedule[] = $s;
 	}
 	/**
 	 * remove time slot $s from the person's schedule if it's there
 	 */
 	function remove_schedule ($s) {
 		$index = array_search($s, $this->schedule);
 		if ($index !== false)
 		   array_splice($this->schedule, $index, 1);
 	}
 	function is_scheduled ($s) {
 		return in_array($s, $this->schedule);
 	}
 	/**
 	 * @param $d is a date "mm-dd-yy" to be added to the Volunteer's work history
 	 */
 	function add_history ($d) {
		$this->history[] = $d;
 	}
 	/**
 	 * remove the most distant date from the Volunteer's work history
 	 */
 	function remove_history () {
 		array_splice($this->history, 0, 1);
 	}
    function set_public_notes($n){
		$this->public_notes = $n;
	}
	function set_my_notes($n){
		$this->my_notes = $n;
	}
    function set_private_notes($n){
		$this->private_notes = $n;
	}
    function set_password($pw){
		$this->password = md5($pw);
	}
 }

?>
